package com.fh.wanandroid.ui.navigation.presenter;

import android.util.Log;

import com.fh.wanandroid.net.RetrofitHelper;
import com.fh.wanandroid.ui.mainpager.MainPagerContract;
import com.fh.wanandroid.ui.mainpager.bean.FeedArticleListData;
import com.fh.wanandroid.ui.navigation.bean.NavigationData;
import com.fh.wanandroid.ui.navigation.contract.NavigationContract;
import com.fh.wanandroid.utils.NetErrorUtil;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

public  class NavigationPresenter extends NavigationContract.Presenter{


    @Override
     public  void loadNavigationData() {

        mCompositeDisposable.add(RetrofitHelper.createArticleApi().getNavigation()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<NavigationData>() {
                    @Override
                    public void accept(NavigationData navigationData) throws Exception {

                        Log.e("NavigationData","------------------NavigationData:"+navigationData.getData().size());
                        mView.getNavigation(navigationData);
//                        mView.refreshArticles(articleModel.getItems());
//                        mView.appendData(girlBean.getResults());
//                                mView.refreshArticle(articleBean);
//                        Log.e("articleBean","------------------articleBean:"+articleBean.getData().toString());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable t) throws Exception {
//                        mView.loadArticlesFail(NetErrorUtil.handleThrowable(t));
                        mView.loadDataFail(NetErrorUtil.handleThrowable(t));
                    }
                }));


    }

}
